﻿
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Kernel;
using NoobOS.FileSystem.Physical;
using NoobOS.FileSystem.Physical.Drivers;
using NoobOS;
using Cosmos.Hardware;
namespace CosmosKernel1.Core
{
    class Init
    {
        public bool activate;
        public int window;
        
        public int ram;
        public int zarad;







        public static void init()
        {
            string version;
            version = "1.0.0.0.1.2.3.9.5";
     
            Power.ACPI.Init();
            string input;
 
            Console.Clear();

        n:
            Console.Write("World Dos>");

            input = Console.ReadLine();
            if (input == "calc")
            {
                string y;
            calc:
                Calc.unit();
                Console.Write("Something to continue to work in the calculator, press y or to exit press n>");
                y = Console.ReadLine();
                if (y == "n")
                {
                    goto n;
                }
                else
                {
                    goto calc;
                }
            }

            else if (input == "disks")
            {
                IDE[] IDEDevices = new IDE[IDE.Devices.Count];
                VGAScreen VGA = new VGAScreen();
                VGA.SetTextMode(VGAScreen.TextSize.Size80x25);
                VGA.Clear(4);
                //Console.BackgroundColor = ConsoleColor.DarkBlue;
                Console.ForegroundColor = ConsoleColor.Gray;

                Console.WriteLine("Initializing ATA...\n\nScanning...\n");
                ATABus ATA01 = new ATABus(0, 1);
                Console.WriteLine("PORT " + ATA01.BusPort + " ST " + ATA01.ControllerPort + "\n\n");
                ATABus ATA11 = new ATABus(1, 1);
                Console.WriteLine("PORT " + ATA11.BusPort + " ST " + ATA11.ControllerPort + "\n\n");

                Console.WriteLine("Initializing IDE..\n\nScanning...\n");

                for (int x = 0; x < IDE.Devices.Count; x++)
                {
                    Console.WriteLine("Device at " + x + ": " + IDE.Devices[x].BlockCount + "\n");
                    IDEDevices[x] = IDE.Devices[x];
                }

                Console.WriteLine("Initializing ATAPI ...\n\nSearching for Hardware on bus 1...\n");

                AtapiHandler p0 = new AtapiHandler(1);
                Console.WriteLine(p0.ModelNo + " ");
                Console.WriteLine(p0.SerialNo + " ");
                Console.WriteLine(p0.FirmwareRev + " ");

                Console.WriteLine("\n\nAttempt to read in bus 1...\n");
                Byte[] data = new Byte[p0.BlockSize];
                bool s = true;
                try
                {
                    p0.ReadBlock(0, 1, data);
                }
                catch
                {
                    //Console.WriteLine(Utils.byteArrayToByteString(data));
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("FAILED TO READ ON BUS 1!\n");
                    s = false;
                }
                if (s)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Success...\n");
                }
                

            }
            else if (input == "clear")
            {
                Console.Clear();


            }
            else if (input == "W")
            {

                Class1.init();
            }
            else if (input == "about")
            {

                Console.WriteLine("ANDOS® version"+version);
                Console.WriteLine("create:Andrew Konstantinov");
                var ram = Cosmos.Core.CPU.GetAmountOfRAM();
                Console.WriteLine("Your system has:");
                Console.WriteLine(ram + " " + "MegaBytes");
                Console.WriteLine("of ram memory");
                goto n;
            }
            else if (input == "reboot")
            {
                Cosmos.Core.Global.CPU.Reboot();

            }
            else if (input == "time")
            {
                Console.Write("24-hours time: ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(times.TwentyFourHourToString());
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("12-hours time: ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine(times.TwelveHourToString());
                Console.Write(times.Day.ToString());
                Console.Write(":");
                string g="0";
                int f;
                f = Cosmos.Hardware.RTC.Month; 
                if (f<= 10)
                {
                  g = g+Cosmos.Hardware.RTC.Month.ToString();
                }
                Console.Write(g);
                Console.Write(":");
                Console.WriteLine(times.Year.ToString());
                Console.ForegroundColor = ConsoleColor.White;
            }
            else if (input == "off" || input=="shitdown")
            {
                Textscreen.ShutdownScreen.ShowShutdownScreen();
            }
            else if (input == "install")
            {
              
            }
            else if (input == "help")
            {
                Console.WriteLine("off -- for shitdown ");
                Console.WriteLine("time--for time");
                Console.WriteLine("reboot -- for reboot ");
                Console.WriteLine("about--for about");
                Console.WriteLine("W -- GUI system destable version");
                Console.WriteLine("clear--clear the console");
                Console.WriteLine("calc -- for calculator ");
                Console.WriteLine("disks--for disks searh");
            }
            else
            {
                Console.WriteLine("error");
            }
            goto n;


        }
        }
}
